<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <script src="../js/jquery.1.9.min.js"></script>
    <script src="https://cdn.bootcss.com/semantic-ui/2.2.4/semantic.js"></script>
</head>

<script>
    $(function () {
        $(".ui.dropdown").dropdown();
        var c_list = "";
        $.get("/wenote/category?method=findAllCategoryByPage", {}, function (data) {
            for (var i = 0; i < data.list.length; i++) {
                c_list += '<div class="item" data-value="' + data.list[i].categoryName + '">' + data.list[i].categoryName + '</div>'
            }
            $("#category").html(c_list);
        });

        var t_list="";
        $.get("/wenote/tag?method=findAllTagByPage", {}, function (data) {
            for (var i = 0; i < data.list.length; i++) {
                t_list += '<div class="item" data-value="' + data.list[i].tagName + '">' + data.list[i].tagName + '</div>'
            }
            $("#tag").html(t_list);
        });

        function checkTitle() {
            var flag;
            var noteTitle=$("#noteTitle").val();
            if(noteTitle==null || noteTitle.trim().length<=0){
                flag=false;
                $("#error_msg").html("博客标题不能为空");
            }else{
                flag=true;
            }
            return flag;
        }

        function checkTag() {
            var flag;
            var tagName=$("#tagName").val();
            if(tagName==null || tagName.trim().length<=0){
                flag=false;
                $("#error_msg").html("标签不能为空");
            }else{
                flag=true;
            }
            return flag;
        }

        function checkCategory() {
            var flag;
            var categoryName=$("#categoryName").val();
            if(categoryName==null || categoryName.trim().length<=0){
                flag=false;
                $("#error_msg").html("分类不能为空");
            }else{
                flag=true;
            }
            return flag;
        }

        function checkNoteContent() {
            var flag;
            var noteContent=$("#noteContent").val();
            if(noteContent==null || noteContent.trim().length<=0){
                flag=false;
                $("#error_msg").html("博客内容不能为空");
            }else{
                flag=true;
            }
            return flag;
        }

        $("#publish-btn").click(function () {
            if(checkTitle() && checkCategory() && checkTag() & checkNoteContent()){
                $.post("/wenote/note?method=addNote",$("#blog-form").serialize(),function (data) {
                    if(data.flag){
                        alert("添加成功");
                        location.reload();
                    }else{
                        alert(data.errorMsg);
                    }
                });
            }
        });

        $("#noteTitle").blur(checkTitle);
        $("#noteContent").blur(checkNoteContent);
        $("#categoryName").blur(checkCategory);
        $("#tagName").blur(checkTag);
    });
</script>

<body>

<!-- 中间内容 -->
<div style="margin-top: 5%;" class="m-padding-tb-large" style="zoom: 0.8 !important;">
    <div class="ui container m-container">
        <div id="error_msg" style="color: red; text-align: center;"></div>
        <form id="blog-form" action="#" method="post" class="ui form">
            <input type="hidden" name="published">
            <input type="hidden" name="id">
            <div class="required field">
                <div class="ui left labeled input">
                    <div class="ui selection dropdown teal m-text-normal basic label">
                        <input type="hidden" value="原创" name="flag">
                        <i class="dropdown icon"></i>
                        <div class="default text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input id="noteTitle" type="text" name="noteTitle" placeholder="标题" autocomplete="off">
                </div>
            </div>

            <div class="required field">
                <div id="context-editormd" style="z-index: 1">
                    <textarea style="display:none;" placeholder="博客内容"></textarea>
                </div>
            </div>

            <div class="two fields">
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input id="categoryName" type="hidden" name="categoryName">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div id="category" class="menu">
                                <div class="item" data-value="1">错误日志</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">标签</label>
                        <div class="ui fluid multiple search selection dropdown">
                            <input id="tagName" type="hidden" name="tagName">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div id="tag" class="menu">
                                <div class="item" data-value="1">c
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="required field">
                <div class="ui left labeled input">
                    <label class="ui basic label">首图</label>
                    <input type="text" name="firstPicture" placeholder="图片地址">
                </div>
            </div>

            <div class="required field">
                <textarea id="noteContent" name="noteContent" placeholder="博客描述..." maxlength="200"></textarea>
            </div>

            <div class="ui error message"></div>
            <div class="ui container right aligned" style="margin-right: 0 !important;">
                <a href="index.html">
                    <button type="button" class="ui button">返回</button>
                </a>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>
        </form>
    </div>
</div>

<script>
    // $('.show').click(function () {
    //     $('.m-item').toggleClass('m-mobile-hide')
    // });
    // $('.ui.dropdown').dropdown();
    // $('.ui.form').form({
    //     fields: {
    //         title: {
    //             identifier: 'title',
    //             rules: [{
    //                 type: 'empty',
    //                 prompt: '标题：请输入博客标题'
    //             }]
    //         },
    //         content: {
    //             identifier: 'content',
    //             rules: [{
    //                 type: 'empty',
    //                 prompt: '标题：请输入博客内容'
    //             }]
    //         },
    //         typeId: {
    //             identifier: 'type.id',
    //             rules: [{
    //                 type: 'empty',
    //                 prompt: '标题：请输入博客分类'
    //             }]
    //         },
    //         firstPicture: {
    //             identifier: 'firstPicture',
    //             rules: [{
    //                 type: 'empty',
    //                 prompt: '标题：请输入首图地址'
    //             }]
    //         },
    //         description: {
    //             identifier: 'description',
    //             rules: [{
    //                 type: 'empty',
    //                 prompt: '标题：请输入博客描述'
    //             }]
    //         }
    //     }
    // });
    // $('#save-btn').click(function () {
    //     $('[name="published"]').val(false);
    //     $('#blog-form').submit();
    // });
    // $('#publish-btn').click(function () {
    //     $('[name="published"]').val(true);
    //     $('#blog-form').submit();
    // });
    // let testEditor;
    // $(function () {
    //     testEditor = editormd({
    //         id: "context-editormd",
    //         width: "100%",
    //         height: 640,
    //         syncScrolling: "single",
    //         path: "/lib/editormd/lib/",
    //         toolbarIcons: function () {
    //             // Or return editormd.toolbarModes[name]; // full, simple, mini
    //             // Using "||" set icons align right.
    //             return ["undo", "redo", "|", "bold", "hr", "|", "watch", "fullscreen", "preview", "testIcon"]
    //         }
    //     });
    // });
</script>
<!--代码放置于</body>上方-->
<script>
    !function () {

        function n(n, e, t) {

            return n.getAttribute(e) || t

        }

        function e(n) {

            return document.getElementsByTagName(n)

        }

        function t() {

            var t = e("script"), o = t.length, i = t[o - 1];

            return {

                l: o, z: n(i, "zIndex", -1), o: n(i, "opacity", .5), c: n(i, "color", "0,0,0"), n: n(i, "count", 99)

            }

        }

        function o() {

            a = m.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,

                c = m.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight

        }

        function i() {

            r.clearRect(0, 0, a, c);

            var n, e, t, o, m, l;

            s.forEach(function (i, x) {

                for (i.x += i.xa, i.y += i.ya, i.xa *= i.x > a || i.x < 0 ? -1 : 1, i.ya *= i.y > c || i.y < 0 ? -1 : 1, r.fillRect(i.x - .5, i.y - .5, 1, 1), e = x + 1; e < u.length; e++) n = u[e],

                null !== n.x && null !== n.y && (o = i.x - n.x, m = i.y - n.y,

                    l = o * o + m * m, l < n.max && (n === y && l >= n.max / 2 && (i.x -= .03 * o, i.y -= .03 * m),

                    t = (n.max - l) / n.max, r.beginPath(), r.lineWidth = t / 2, r.strokeStyle = "rgba(" + d.c + "," + (t + .2) + ")", r.moveTo(i.x, i.y), r.lineTo(n.x, n.y), r.stroke()))

            }),

                x(i)

        }

        var a, c, u, m = document.createElement("canvas"),

            d = t(), l = "c_n" + d.l, r = m.getContext("2d"),

            x = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||

                function (n) {

                    window.setTimeout(n, 1e3 / 45)

                },

            w = Math.random, y = {x: null, y: null, max: 2e4};
        m.id = l, m.style.cssText = "position:fixed;top:0;left:0;z-index:" + d.z + ";opacity:" + d.o, e("body")[0].appendChild(m), o(), window.onresize = o,

            window.onmousemove = function (n) {

                n = n || window.event, y.x = n.clientX, y.y = n.clientY

            },

            window.onmouseout = function () {

                y.x = null, y.y = null

            };

        for (var s = [], f = 0; d.n > f; f++) {

            var h = w() * a, g = w() * c, v = 2 * w() - 1, p = 2 * w() - 1;
            s.push({x: h, y: g, xa: v, ya: p, max: 6e3})

        }

        u = s.concat([y]),

            setTimeout(function () {
                i()
            }, 100)

    }();
</script>
</body>
</html>